package common;

import java.io.Serializable;
import java.time.Duration;
import java.time.LocalTime;

public class Code implements Serializable {
    private String code;
    private LocalTime now;
    public Code(String code){
        this.code=code;
        now=LocalTime.now();
    }
    public static boolean judge(Code code1,Code code2){
        if(code1.getCode().equals(code2.getCode())){
            Duration duration = Duration.between(code1.getNow(), code2.getNow());
            long totalSeconds = duration.getSeconds(); // 获取总秒数
            long hours = totalSeconds / 3600;         // 计算小时数
            long minutes = (totalSeconds % 3600) / 60;// 计算分钟数
            long seconds = totalSeconds % 60;         // 计算剩余的秒钟数
            System.out.println("相差"+minutes+"分"+seconds+"秒");
            if(hours==0&&minutes<=5){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public LocalTime getNow() {
        return now;
    }
}
